#ifndef THREADPOOL_HPP_
#define THREADPOOL_HPP_

#include "Common.hpp"


class Task{
private:
    void *arg;
    void (*callback_function)(void *arg);
public:
    Task() = default;
    Task(void (*_func)(void *arg), void *_arg) : arg(_arg), callback_function(_func)
    {
    }
    void run(){
        (*callback_function)(arg);
    }
};


class ThreadPool
{
private:
    std::queue<Task*> Tasks;
    std::vector<pthread_t> Pthreads;

    pthread_mutex_t TasksLock;
    pthread_cond_t TasksNotEmpty;
    pthread_cond_t NoTasks;

    bool PoolClose;

public:
    void Init();
    int add_job(void (*callback_function)(void *arg), void *arg);
    int destroy();
    static void *thread_function(void* arg);
};

#endif